package flst.ipiweb.struts.action.codepromo;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import flst.ipiweb.service.ServiceCodePromo;
import flst.ipiweb.transverse.CodePromotionnel;

public class ListCodePromoAction extends Action{

	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form,
			HttpServletRequest request, 
			HttpServletResponse response)
			throws Exception {
		
			//On récupère la session
			HttpSession session = request.getSession();
			if(session.getAttribute("login") == null)
			{
				return mapping.findForward("login");
			}
			
			//Récupération de la liste des codes promo
			ServiceCodePromo sCodePromo = new ServiceCodePromo();
			List<CodePromotionnel> listCodePromo = sCodePromo.listerCodePromo();
			request.setAttribute("listCodePromo", listCodePromo);
		
			//Titre de la page
			request.setAttribute("pageTitle", "codepromo.list.title");
			//Activation de l'onglet codepromo
			HashMap<String, String> onglet = new HashMap<String, String>();
			onglet.put("codepromo", "active");
			request.setAttribute("onglet", onglet);
			
			return mapping.findForward("list_code_promo");
		}
}
